<template>
  <page-header-wrapper>
    <page-tab-list></page-tab-list>
    <a-card :border="false">
      <a-form-model ref="ruleForm" :model="form" :rules="rules" :label-col="{ span: 3 }" :wrapper-col="{ span: 12 }">
        <a-form-model-item label="提现方式" prop="pay_type">
          <a-checkbox-group v-model="form.pay_type">
            <a-checkbox value="wechat">微信</a-checkbox>
            <a-checkbox value="alipay">支付宝</a-checkbox>
            <a-checkbox value="bank">银行卡</a-checkbox>
          </a-checkbox-group>
        </a-form-model-item>
        <a-form-model-item label="最少提现" prop="min_money">
          <a-input addonAfter="元" type="number" v-model="form.min_money" />
        </a-form-model-item>
        <a-form-model-item label="每日上线" prop="min_money" help="0元表示不限制每日提现金额">
          <a-input addonAfter="元" type="number" v-model="form.cash_max_day" />
        </a-form-model-item>
        <a-form-model-item
          label="提现手续费"
          prop="min_money"
          help="0表示不设置提现手续费，提现手续费额外从提现中扣除，例如：10%的提现手续费：提现100元，扣除手续费10元， 实际到手90元"
        >
          <a-input addonAfter="%" type="number" v-model="form.cash_service_charge" />
        </a-form-model-item>
        <a-form-model-item :wrapper-col="{ span: 24 }">
          <a-divider style="margin: 0 0 40px 0" />
          <div style="display: flex; justify-content: center">
            <a-button :loading="btnLoading" type="primary" @click="submitForm" style="margin-right: 8px">
              保存
            </a-button>
            <a-button @click="$router.back()"> 取消 </a-button>
          </div>
        </a-form-model-item>
      </a-form-model>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import { getWithdrawSetting, saveWithdrawSetting } from '@/api/saas/marketing'
export default {
  data() {
    return {
      form: {
        pay_type: [],
        min_money: 0,
        cash_max_day: 0,
        cash_service_charge: 0,
      },
      rules: {
        pay_type: [{ required: true, message: '请选择提现方式', trigger: 'change' }],
      },
      btnLoading: false,
    }
  },
  methods: {
    // 获取设置
    async getSetting() {
      this.btnLoading = true
      const res = await getWithdrawSetting({ name: 'share_basic_setting' })
      this.btnLoading = false
      if (res.code == 0 && res.data) {
        this.form.pay_type = res.data.pay_type.value
        this.form.min_money = res.data.min_money.value
        this.form.cash_max_day = res.data.cash_max_day.value
        this.form.cash_service_charge = res.data.cash_service_charge.value
      }
    },
    // 保存设置
    submitForm() {
      this.$refs['ruleForm'].validate(async (valid) => {
        if (valid) {
          this.btnLoading = true
          const res = await saveWithdrawSetting(this.form)
          this.btnLoading = false
          if (res.code == 0) {
            this.$router.back()
          }
        }
      })
    },
  },
  created() {
    this.getSetting()
  },
}
</script>

<style lang="less" scoped>
</style>